#include "tcpserver.hpp"
#include "command.hpp"
#include "dict.hpp"

// ./tcpserver 8080
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cerr << "Usage->" << argv[0] << " port" << std::endl;
        exit(USAGE_ERR);
    }
    uint16_t port = std::stoi(argv[1]);

    // std::unique_ptr<Tcpsocket> tcpserver = std::make_unique<Tcpsocket>(port);

    // 1.翻译
    // Dict d;
    // d.Load();
    // std::unique_ptr<Tcpsocket> tcpserver = std::make_unique<Tcpsocket>(port, [&d](const std::string word, InetAddr &addr){
    //    return d.Translate(word, addr);
    //});

    // 2.远程执行命令
    command cmd;
    std::unique_ptr<Tcpsocket> tcpserver = std::make_unique<Tcpsocket>(port, 
        std::bind(&command::Exexute, &cmd, std::placeholders::_1, std::placeholders::_2));
    //std::unique_ptr<Tcpsocket> tcpserver = std::make_unique<Tcpsocket>(port, 
    //    [&cmd](const std::string &command, InetAddr & addr){
    //        return cmd.Exexute(command, addr);
    //    });

    tcpserver->Init();
    tcpserver->Run();
    return 0;
}
